home *** CD-ROM | disk | FTP | other *** search
- code segment
- assume cs:code
- ; FUNCTION called from Turbo Pascal, which releases
- ; PP_TO_RELEASE paragraphs of memory from the current
- ; memory block using the DOS function 4AH. If this is
- ; possible, then the Turbo stack is relocated to the high
- ; end of the new allocation and function result is zero.
- ; Otherwise the DOS error code is returned.
-
- ; Pascal declaration:
- ; FUNCTION DOS4AH(PP_TO_RELEASE:INTEGER):INTEGER;
-
- arguments struc ; Template to arguments.
- save_bp dw ? ; Saved BP register.
- ret_adr dw ? ; Return address (near call).
- ;-------------------------------------------------------------------
- pp_to_release dw ? ; INTEGER # of paragraphs
- ; to release.
- ;-------------------------------------------------------------------
- arguments ends
-
- dos4AH proc near
- push bp
- mov bp,sp ; Establish access to arguments
- push ds ; Save Turbo's data segment.
-
- mov ax,cs ; Calculate the paragraph size
- mov bx,ss ; of the current block as
- add bx,1000H ; SS+1000H minus code segment
- sub bx,ax ; address. Then calculate new
- ; size for memory block.
- sub bx,[bp].pp_to_release
- mov es,ax ; Segment address of current
- mov ah,4ah ; memory block.
- int 21h ; Ask DOS to deallocate the space.
- mov ah,0
- jc exit ; Was it possible to release
- ; the memory?
- mov ax,ss ; Yes: set up to relocate stack
- mov ds,ax ; DS:SI is pointer to old stack
- sub ax,[bp].pp_to_release
- mov es,ax ; ES:DI is the pointer to
- mov bx,sp ; the new stack.
- mov di,bx
- mov si,bx
-
- mov cx,sp ; Two's complement of SP
- neg cx ; is stack size.
- cld ; Move cx bytes from
- rep movsb ; DS:SI to ES:DI ...
- ; starting with the lowest byte
- mov ss,ax ; Change the SS register ...
- xor ax,ax ; and set the error code to 0.
- exit: pop ds
- pop bp
- ret 4 ; Pop argument and
- dos4AH endp ; "function result".
- code ends
- end
-